package com.artqiyi.dollmachine.utils.Callback;

import com.artqiyi.dollmachine.model.entity.ErrorBean;
import com.artqiyi.dollmachine.utils.JSONUtils;
import com.zhy.http.okhttp.callback.Callback;

import okhttp3.Response;

/**
 * Created by zhy on 15/12/14.
 */
public abstract class MyStringCallback extends Callback<String> {
    @Override
    public boolean validateReponse(Response response, int id) {
        return true;
    }

    @Override
    public String parseNetworkResponse(Response response, int id) throws Exception {
        if (response.code() >= 200 && response.code() < 300) {
            return response.body().string();
        } else {
            throw new Exception(JSONUtils.jsonString2Bean(response.body().string(), ErrorBean.class).getMessage());
//            throw new Exception("code is:" + response.code() + "\n" + response.body().string());
        }

    }
}
